/**
 * Copyright (c) 2007, Ashish Lijhara
 * All rights reserved.
 *
 * ReflectionPanel.java
 *
 */

package crazy.java.Aetas;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import javax.imageio.ImageIO;
import javax.swing.JPanel;


/**
 *
 * @author Ashish a.k.a Java Crazy
 */
public class ReflectionPanel extends JPanel {
    private BufferedImage image;
    private BufferedImage imageA;
    private ReflectionRenderer renderer;
    
    public Dimension getPreferredSize() {
        return new Dimension(250, 250);
    }
    
    protected void paintComponent(Graphics g) {
        int x = (getWidth() - imageA.getWidth()) / 2;
        int y = 24;
        g.drawImage(imageA, x, y, null);
        g.drawImage(image, x, y + imageA.getHeight(), null);
    }
    
    public ReflectionPanel(String s,String zone,String clock) {
        setLayout(new GridBagLayout());
        renderer = new ReflectionRenderer(0.5f,0.3f,false);
        try {
            File file = new File(s);
            imageA = ImageIO.read(new URL(file.toURI().toURL().toString()));
        } catch(IOException e) {
            e.printStackTrace();
        }
        image = renderer.createReflection(imageA);
        GridBagConstraints c = new GridBagConstraints();
        c.fill = GridBagConstraints.HORIZONTAL;
        clockHandler ch=new clockHandler(imageA.getWidth(),imageA.getHeight(),zone,clock);
        c.insets=new Insets(-2,0,0,0);
        c.gridx=0;
        c.gridy=0;
        add(ch,c);
        ch.start();
        setOpaque(false);
        
        
    }
}
